<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>项目列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/templates/act/process-xl.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<p style="font-size: 14px;font-weight: bold;">
    <span>流程当前办理阶段:</span>
    <span class="stage" style="color: #0000FF"></span>
</p>
<h1 style="text-align: center;margin:10px 0;">
    勘察报告人员信息表
</h1>
<form class="layui-form layui-form-pane" action="" lay-filter="example">
    <div class="layui-form-item">
        <label class="layui-form-label">项目负责人</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="kcProjectLeaderName" readonly>
        </div>
        <label class="layui-form-label" style="width:118px;">注册职业资格</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="kcLeaderRegisterQualification" readonly>
        </div>
        <label class="layui-form-label">证书编号</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="kcLeaderCerNum" readonly>
        </div>
    </div>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    <div class="layui-btn-container">
        <button class="layui-btn" lay-event="add">新增</button>
        <button class="layui-btn" lay-event="delete">删除</button>
        <button class="layui-btn" lay-event="deletes">批量删除</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="change">修改</a>
</script>

<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    var configureCom = {};
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'matchDict', 'form'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var matchDict = layui.matchDict;
        var form = layui.form;
        configureCom = layui.configureCom;
        var stage = sessionFun.get(configure.SESSION_PROJECT_WAIT_LIST_DATA);
        $('.stage').html(stage.taskDefName);
        var listData = sessionFun.get(configure.SESSION_PROJECT_WAIT_LIST_DATA);
        form.val('example', listData);
        var cols = [[
            {type: 'checkbox'},
            {
                field: 'roleType', title: '工程担任角色', templet: function (d) {
                    var roleCode = configure.KCDRJS;
                    return '<p>' + matchDict.name(d.roleType, roleCode) + '</p>';
                }
            },
            {
                field: 'specialtyId', title: '所属专业', templet: function (d) {
                    return '<p>' + matchDict.name(d.specialtyId, configure.KC_SPE) + '</p>';
                }
            },
            {
                field: 'userName', title: '人员姓名'
            }, {
                field: 'qualificationCertificateName', title: '人员证书信息', templet: function (d) {
                    return '<p>' + (d.qualificationCertificateName || '-') + '</p><p>(证书编号' + (d.qualificationCertificateNum || '-') + ')</p>';
                }
            },
            {
                field: 'linkPhone', title: '联系电话',templet: function (d) {
                    return '<p>' + (d.linkPhone || '-')+'</p>';
                }
            },
            {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150}
        ]];
        configureCom.tableRender(configure.PRJ_REPORT_LIST_HTTP, {
            orgType: configure.KC_CODE,
            decId: listData.decId
        }, cols, 'dataList', 10, 'full-200', 'toolbarOrg');
        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            sessionFun.remove(configure.SESSION_KCSJ_REPORT_PEOPLE_LIST_DATA);
            switch (obj.event) {
                case 'add':
                    editItem('添加人员', configure.PRJ_REPORT_SAVE_HTTP);
                    break;
                case 'delete':
                    if (checkStatus.data.length == 0) {
                        top.layer.alert('请选择数据！');
                    } else {
                        deleteFun(checkStatus.data);
                    }
                    break;
                case 'deletes':
                    if (checkStatus.data.length == 0) {
                        top.layer.alert('请选择数据！');
                    } else {
                        deleteFuns(checkStatus.data);
                    }
                    break;
            }
        });
        //单个删除
        function deleteFun(data) {
            top.layer.confirm('您真的要删除这条数据吗？', function () {
                var personIds = configureCom.dataConcat(data, 'personId');
                configureCom.postDataAjax(configure.PRJ_PERSON_DELETE_HTTP, {personId: personIds}).then(function (res) {
                    if (res.code == 0) {
                        top.layer.msg('删除成功！');
                        configureCom.tableReload(true);
                    } else {
                        top.layer.alert('删除失败！');
                    }
                });
            });
        }
        //批量删除
        function deleteFuns(data) {
            top.layer.confirm('您真的要删除这条数据吗？', function () {
                var personIds = configureCom.dataConcat(data, 'personId');
                configureCom.postDataAjax(configure.PRJ_REPORT_DELETE_BATCH_HTTP, {personIds: personIds}).then(function (res) {
                    if (res.code == 0) {
                        top.layer.msg('删除成功！');
                        configureCom.tableReload(true);
                    } else {
                        top.layer.alert('删除失败！');
                    }
                });
            });
        }

        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_KCSJ_REPORT_PEOPLE_LIST_DATA, data);
            if (obj.event === 'change') {
                editItem('修改', configure.PRJ_REPORT_SAVE_HTTP);
            } else if (obj.event === 'del') {
                //关闭时重新渲染表格当前页
                top.layer.confirm('确认删除？', {title: '提示'}, function (index) {
                    top.layer.close(index);
                    configureCom.postDataAjax(configure.UNIT_ITEM_DELETE_HTTP, {prjId: data.prjId}).then(function (res) {
                        if (res.code == 0) {
                            top.layer.msg('删除成功！');
                            configureCom.tableReload(true);
                        } else {
                            top.layer.alert('删除失败！');
                        }
                    });
                });
            }
        });

        //新增或修改详情
        function editItem(title, url) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(configure.PRJ_KCSJ_REPORT_DETAIL_HTML + '?specType=' + configure.KC_CODE),
                btn: ['保存', '保存并再次新增'],
                yes: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        configureCom.postDataAjax(url, res.result).then(function (res) {
                            console.log(res);
                            top.layer.close(index);
                            top.layer.msg('保存成功！');
                            configureCom.tableReload(true);
                        });
                    });
                },
                btn2: function (index, layero) {
                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
                    iframeWin.getData().then(function (res) {
                        configureCom.postDataAjax(url, res.result).then(function (res) {
                            top.layer.close(index);
                            top.layer.msg('保存成功！');
                            configureCom.tableReload(true);
                            sessionFun.remove(configure.SESSION_KCSJ_REPORT_PEOPLE_LIST_DATA);
                            editItem('添加', configure.PRJ_REPORT_SAVE_HTTP);
                        });
                    });
                    return false;
                }
            });
        }

        //监听搜索
        configureCom.tableSearch();
    });
</script>
</body>
</html>